using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using ContentBanner.Models;
using Orchard.Settings;
using Orchard.Localization;
namespace ContentBanner.Drivers {
    public class ContentBannerSettingsPartDriver : ContentPartDriver<ContentBannerSettingsPart> {
        private readonly ISiteService _siteService;

        public Localizer T { get; set; }

        public ContentBannerSettingsPartDriver(ISiteService siteService) {
            _siteService = siteService;
            T = NullLocalizer.Instance;
        }

        protected override string Prefix { get { return "ContentBannerSettings"; } }

        protected override DriverResult Editor(ContentBannerSettingsPart part, dynamic shapeHelper)
        {
            var contentBannerSettingsPart = _siteService.GetSiteSettings().As<ContentBannerSettingsPart>();

            return ContentShape("Parts_Settings_ContentBannerSettingsPart", () =>
                shapeHelper.EditorTemplate(
                TemplateName: "Parts.Settings.ContentBannerSettingsPart",
                Model: contentBannerSettingsPart,
                Prefix: Prefix)).OnGroup("Content Banner");
        }

        protected override DriverResult Editor(ContentBannerSettingsPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var contentBannerSettingsPart = _siteService.GetSiteSettings().As<ContentBannerSettingsPart>();

            updater.TryUpdateModel(contentBannerSettingsPart, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}